<template>
	<view class="list-page" :style="loading ? 'opacity: 0;' : 'opacity: 1;'">
		<!--  v-model="dataList" @query="queryList" -->
		<!--  refresher-only @onRefresh="onRefresh" -->
		<pageTxt>
			<listTabCom class="listTabCom" :tabList="topTabListArr" @topTabClick="topTabClick" :current="topTabIndex"></listTabCom>
			<!-- 预算管理 -->
			<budgetManagement ref="bm" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 1"></budgetManagement>
			<!-- 结算管理 -->
			<settlementManagement ref="sm" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 2"></settlementManagement>
			<!-- 增减项管理 -->
			<increaseDecreaseItems ref="idi" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 3"></increaseDecreaseItems>
		</pageTxt>
	</view>
</template>

<script>
import budgetManagement from './components/budgetManagement/budgetManagement.vue';
import settlementManagement from './components/settlementManagement/settlementManagement.vue';
import increaseDecreaseItems from './components/increaseDecreaseItems/increaseDecreaseItems.vue';
export default {
	components: {
		increaseDecreaseItems,
		settlementManagement,
		budgetManagement
	},
	data() {
		return {
			loading: true,
			dataList: [],
			conentHeight: 0,
			topTabIndex: '-1',
			showIndex: 0,
			topTabList: [
				{
					name: '预算管理',
					menu: '/ysgl',
					key: 1
				},
				{
					name: '结算管理',
					menu: '/jsgl',
					key: 2
				},
				{
					name: '增减项管理',
					menu: '/zjxgl',
					key: 3
				}
			],
			topTabListArr: []
		};
	},
	onShow() {
		// 请求更新某条数据
		this.$nextTick(() => {
			switch (Number(this.showIndex)) {
				case 1:
					if (!this.$refs.bm) return;
					this.$refs.bm.updateListIdx();
					break;
				case 2:
					if (!this.$refs.sm) return;
					this.$refs.sm.updateListIdx();
					break;
				case 3:
					if (!this.$refs.idi) return;
					this.$refs.idi.updateListIdx();
					break;
			}
		});
	},
	onLoad(option) {
		this.getHeight();
		// 菜单权限判断
		let topTabListArr = [];
		this.topTabList.forEach((item) => {
			if (this.$menuShow(item.menu)) {
				topTabListArr.push(item);
			}
		});
		this.topTabListArr = topTabListArr;
		// 页面参数处理
		if (option.tabIndex) {
			let index = topTabListArr.findIndex((item) => {
				return item.key == option.tabIndex;
			});
			this.topTabIndex = index;
			this.showIndex = option.tabIndex;
		}
		this.$nextTick(() => {
			if (option.project_name) {
				switch (Number(this.showIndex)) {
					case 1:
						break;
					case 2:
						break;
					case 3:
						if (!this.$refs.idi) return;
						this.$refs.idi._data.searchForm.project_name = option.project_name;
						this.$refs.idi.searchFunc();
						break;
				}
			}
		});
	},
	methods: {
		getHeight() {
			// 创建节点查询
			let that = this;
			const systemInfo = uni.getSystemInfoSync();
			const query = uni.createSelectorQuery().in(that);
			query.select('.listTabCom').boundingClientRect();
			query.exec((res) => {
				that.conentHeight = systemInfo.screenHeight - (res[0].height + 20); //组件可用高度 20状态栏高度（动态获取高度不包含状态栏高度）
				setTimeout(() => {
					that.loading = false;
				}, 200);
			});
		},
		topTabClick(index) {
			this.topTabIndex = index;
			this.showIndex = this.topTabListArr[index].key;
		}
	}
};
</script>

<style lang="scss" scoped></style>
